/**
 * 商品模块接口文件
 */

import axios from './request';
import { IPage, IPageResult } from './common';

/**
 * 添加商品接口
 */
export interface IAddGoods {
    name: string;
    class_id: number;
    price: number;
    oldPrice: number;
    sku: number;
    quantity: number;
    weight: number;
}

/**
 * 商品接口
 */
export interface IGoods extends IAddGoods {
    id: number;
    status: number;
    creation_time: Date;
}

/**
 * 修改商品类型
 */
export type UpdateGoodsType = Omit<IGoods, 'status' | 'creation_time'>;

/**
 * 更改商品状态类型
 */
export type ChangeGoodsStatusType = Pick<IGoods, 'id' | 'status'>;

/**
 * 搜索类型
 */
export type SearchType = Partial<Pick<IGoods, 'status' | 'name' | 'class_id' | 'price'>> & IPage & {
    end_price?: number;
}

/**
 * 获取列表
 * @returns 
 */
export const search = async (model: SearchType): Promise<IPageResult<IGoods>> => axios.get('/goods/search', { params: model });

/**
 * 添加
 * @param model 
 * @returns 
 */
export const add = async (model: IAddGoods) => axios.post('/goods/add', model);

/**
 * 修改
 * @param model 
 * @returns 
 */
export const update = async (model: UpdateGoodsType) => axios.put('/goods/update', model);

/**
 * 删除
 * @param id 
 * @returns 
 */
export const changeStatus = async (model: ChangeGoodsStatusType) => axios.put('/goods/changeStatus', model);